﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Messaging;
using Bymed.SpineScan.WPF.Shared;
using Bymed.SpineScan.DataModel;
using Bymed.SpineScan.WPF.ViewModel;

namespace Bymed.SpineScan.WPF
{
    /// <summary>
    /// Interaction logic for SelectTestItemPage.xaml
    /// </summary>
    public partial class SelectTestItemPage : PageBase
    {
        public SelectTestItemPage()
        {
            InitializeComponent();
            InitializePageUnloadStoryboard();
        }

        protected override void RegisterMessages()
        {
            base.RegisterMessages();
            RegisterSelectTestItemGoToNextPageMessage();
        }

        private void CurrentPage_Loaded(object sender, RoutedEventArgs e)
        {
            AttendingDoctorList.SelectedIndex = 0;
        }

        /// <summary>
        /// Register this message that happens when user finished test item selection.
        /// </summary>
        private void RegisterSelectTestItemGoToNextPageMessage()
        {
            Messenger.Default.Register<SelectTestItemViewModel>(this, 
                SelectTestItemViewModel.GoToNextPageMessageToken, selectTestItemViewModel =>
            {
                try
                {
                    var startTestPage = new StartTestPage();
                    var startTestViewModel = startTestPage.DataContext as StartTestViewModel;
                    ViewModelHelper.CopyTestItemAndAllRelatedInfoReference(selectTestItemViewModel, startTestViewModel);
                    startTestViewModel.ResetProperties();

                    GoToPage(startTestPage, false);
                }
                catch (Exception ex)
                {
                    MyViewModelBase.RequestDisplayErrorMessage(ex.Message);
                }
            });
        }

        private void ButtonBack_Click(object sender, RoutedEventArgs e)
        {
            GoToPage(new PatientBasicInfoPage(), false);
        }
    }
}
